package com.heima.order.config;

import com.heima.constant.MQConstant;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MQConfig {

    @Bean
    public DirectExchange create_order_exchange(){
        DirectExchange exchange = ExchangeBuilder.directExchange(MQConstant.CREATE_ORDER_EXCHANGE).build();
        return exchange;
    }
    @Bean
    public Queue deduct_stock_queue(){
        Queue queue = QueueBuilder.durable(MQConstant.DEDUCT_STOCK_QUEUE).build();
        return queue;
    }
    @Bean
    public Queue del_cart_goods_queue(){
        Queue queue = QueueBuilder.durable(MQConstant.DEL_CART_GOODS_QUEUE).build();
        return queue;
    }
    @Bean
    public Binding  deduct_stock_rk(){
        Binding binding = BindingBuilder.bind(deduct_stock_queue()).to(create_order_exchange()).with(MQConstant.DEDUCT_STOCK_RK);
        return binding;
    }
    @Bean
    public Binding  del_cart_goods_rk(){
        Binding binding = BindingBuilder.bind(del_cart_goods_queue()).to(create_order_exchange()).with(MQConstant.DEL_CART_GOODS_RK);
        return binding;
    }


}
